//
//  RestAPI.swift
//  jiahui
//
//  Created by 3tee on 2024/11/25.
//

import Foundation
import Moya

enum RestAPI {
    case getToken(String)
    case login(email: String,pwd: String)
    case getRoomToken(name :String,roomId :String)
    //case getAppVersion(client_type: String, version: String, site_id: String, app_scheme: String, token: String)
    case getAppVersion(String,String,String,String,String)
    
}

extension RestAPI: TargetType{
    var baseURL: URL {
        return URL(string:Constant.mediaSever)!
    }
    
    var path: String {
        switch self {
        case .getToken:
            return "/avd2api/v1/certificate/get"
        case .login:
            return "/avd2api/v1/auth/login"
        case .getRoomToken:
            return "/avd2api/v1/auth/get_room_token"
        case .getAppVersion:
            return "/avd2api/v1/system/get_version"
        }
    
        
    }
    
    var method: Moya.Method {
        switch self {
        case .login , .getAppVersion ,.getToken:
                .post
        case .getRoomToken:
                .get
        }
    }
    
    var task: Moya.Task {
        switch self {
        case let .getToken(rsaJson):
            let parms = ["data":rsaJson]
            return Task.requestParameters(parameters: parms, encoding: URLEncoding.default)
        case .login(let email, let pwd):
            let parms = ["email":email,"password":pwd]
            return Task.requestParameters(parameters: parms, encoding: URLEncoding.default)
        case .getRoomToken(let name, let roomId):
            let parms = ["name":name,"room_id":roomId]
            return Task.requestParameters(parameters: parms, encoding: URLEncoding.default)

        case let .getAppVersion(type, version, site_id, app_scheme, token):
            let parms = ["client_type":type,"self_version":version,"site_id":site_id,"app_scheme":app_scheme,"token":token]
            return Task.requestParameters(parameters: parms, encoding: URLEncoding.default)
            
            
        }
        
    }
    
    var headers: [String : String]? {
        switch self {
         default:
            return ["Content-Type": "application/x-www-form-urlencoded"]
        }
        
    }
}
